#include "GameEngine.h"

GameEngine::GameEngine()
{
    head = new HeadTracker();
    ball = new Ball();
    track = new BallTrack();
}

GameEngine::~GameEngine(){

}



void GameEngine::setBallPosition(int head_pos_x,int head_pos_y){



}

void GameEngine::update(int timeR){

    head->update();

    ball->setProgress(ball->speed*timeR/1000.0);
    ball->setZone(head->face_pos_x, track->getNbTracks());


    ball->speed *= 1.0 + 0.00001*timeR;


    int s = track->getTab(floor(ball->getProgress())*track->getNbTracks() + ball->getZone());
    switch(s){
        case 1: // pas un trou
            break;
        case 0 : // trou, on fait tomber la boule
            ball->isDying=true;
            break;
        case 2 :// Acceleration
            ball->speed *= 1.0 + 0.0003*timeR;
            break;
        case 3 :// Slow
            ball->speed *= 1.0 - 0.0001*timeR;
            break;

    }

    if(ball->isDying)
        ball->decAltitude(timeR/1000.0);
    if(ball->isDead())
        ball->reset();

}

void GameEngine::drawElements(){

    glPushMatrix();
        glTranslatef(-(track->getBlockLargeur()*track->getNbTracks())/2,0.0,(ball->getProgress()-1)*track->getBlockLongueur());
        track->draw();
    glPopMatrix();

    glPushMatrix();
    glTranslatef(head->face_pos_x/55.0,0.5 + ball->getAltitude(),0.0);
    ball->draw();
    glPopMatrix();

}
